/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef FILE_STREAMER_H
#define FILE_STREAMER_H

#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <boost/shared_ptr.hpp>

#include "../model/title.h"
using namespace std;

/** 
 * \brief This namespace includes all music-related stuff.
 * \author Michael Opitz
 */
namespace music {
	/** 
	 * \brief This class loggs the played titles.
	 */
	class file_streamer {
	public:
		/** 
		 * \brief file_streamer creates a file_streamer object.
		 * 
		 * \param file is the file which should be opened. Usually this
		 * is `client_name`.txt
		 */
		file_streamer(const string &file)
		:_file(file) { create_file(file); } 
		~file_streamer() {};

		/** 
		 * \brief append_title appends a title, which was played, to the file.
		 * 
		 * \param title is a shared_ptr to a title
		 */
		void append_title(boost::shared_ptr<model::title> title);
		/** 
		 * \brief read_file reads all the played titles from the file
		 * 
		 * \return a list of shared_ptrs to titles.
		 */
		list<boost::shared_ptr<model::title> > read_file();

		/** 
		 * \brief list_files lists all available files.
		 * 
		 * \return a list of strings which stores the filenames (e.g.
		 * client1.txt, client2.txt, ...) is returned.
		 */
		list<string> list_files();
		/** 
		 * \brief create_file creates a new file
		 * 
		 * \param name is the name of the new file
		 */
		void create_file(const string &name);
	private:
		string _file;
	};
}

#endif
